import { defineStore } from 'pinia'
import { locGet, locSet } from '@/utils/common'
import type { RootState, quickNavDataItem } from './types/index'

export const commonStore = defineStore('commonStore', {
  state: (): RootState => ({
    const: 0,
    space: '',
    locale: locGet('locale') || 'zhCN',
    // identity: ['admin', 'visitor', 'vip'], // 身份权限，和指令v-permission联合使用
    identity: ['visitor'], // 身份权限，和指令v-permission联合使用
    isExpandNav: false,
    quickNavData: locGet('quickNavData', 'O') || [],
    keepAlive: false,
    navKey: 'dataManagement',
  }),
  actions: {
    setLocale(data: string) {
      this.locale = data
      locSet('locale', data)
    },
    changeNavStatus(data: boolean) {
      this.isExpandNav = data
    },
    addBreadcrumb(data: quickNavDataItem) {
      this.quickNavData.push(data)
      locSet('quickNavData', this.quickNavData)
    },
    delBreadcrumb(i: number) {
      this.quickNavData.splice(i, 1)
      locSet('quickNavData', this.quickNavData)
    },
    setKeepAlive(data: boolean) {
      this.keepAlive = data
    },
  },
  getters: {
    count(state) {
      return state.quickNavData
    },
  },
})
